package com.shop2cn.iapi.shenqisettlement.testcase;

import com.shop2cn.iapi.shenqisettlement.parameter.bean.GetCurrencyConfigBean;
import com.shop2cn.iapi.shenqisettlement.parameter.resp.GetCurrencyConfigResp;
import com.shop2cn.iapi.shenqisettlement.service.GetCurrencyConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.shenqisettlement.CurrencyConfig;
import com.ymttest.database.sqlwapper.shenqisettlement.CurrencyConfigWrapper;
import com.ymttest.utils.DataUtil;

import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

/**
 * 根据国家获取汇率 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetCurrencyConfig {
	private static GetCurrencyConfigBean getcurrencyconfigBean;
	private static GetCurrencyConfigCall getcurrencyconfigCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据国家获取汇率");
	}

	@Before
	public void caseUp() {
		getcurrencyconfigBean = new GetCurrencyConfigBean();
		getcurrencyconfigCall = new GetCurrencyConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getcurrencyconfigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	public void verify(GetCurrencyConfigResp expectObject) {

		CurrencyConfigWrapper wrapper = new CurrencyConfigWrapper();

		CurrencyConfig actualObject = wrapper
				.selectByPrimaryKey(getcurrencyconfigBean.getCurrency());

		Logger.verifyEquals(expectObject.getCurrency(),
				actualObject.getCurrency_code(), "验证currency");
		Logger.verifyEquals(expectObject.getMark(),
				actualObject.getCurrency_mark(), "验证mark");
		Logger.verifyEquals(expectObject.getName(),
				actualObject.getCurrency_name(), "验证name");
		DataUtil.verifyDecimalEquals(expectObject.getExchangeRmbRate(),
				actualObject.getHp_exchange_rmb_rate(), "验证exchangeRmbRate");
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetCurrencyConfig_001() {
		Logger.start(true, "根据币种获取汇率信息");
		try {

			getcurrencyconfigBean.setCurrency("USD");
			getcurrencyconfigCall.setData(getcurrencyconfigBean);

			getcurrencyconfigCall.callService();

			GetCurrencyConfigResp currencyConfigResp = getcurrencyconfigCall
					.getCurrencyConfigResp();

			this.verify(currencyConfigResp);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetCurrencyConfig_002() {
		Logger.start(true, "根据未知币种获取汇率信息");
		try {

			getcurrencyconfigBean.setCurrency("asd");
			getcurrencyconfigCall.setData(getcurrencyconfigBean);

			getcurrencyconfigCall.callService();

			Logger.verifyEquals(null,
					new JSONObject(getcurrencyconfigCall.getReturnData())
							.optJSONObject("result"), "验证currencyConfigResp");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}